//
//  CJBaseModel.m
//  DatangLife
//
//  Created by 娜 on 2018/4/19.
//  Copyright © 2018年 DatangLife. All rights reserved.
//

#import "CJBaseModel.h"
#import "MJExtension.h"
#import "CJFileCacheManager.h"

@implementation CJBaseModel

MJCodingImplementation;
//- (NSString *)img{
//    NSString *str1 =  [_img stringByReplacingOccurrencesOfString:@"//" withString:@"/"];
//    NSString * str2 = [str1 stringByReplacingOccurrencesOfString:@"\\" withString:@"/"];
//    return str2;
//}
//+ (NSDictionary *)replacedKeyFromPropertyName {
//    return @{
//             };
//}

+ (NSMutableArray *)modelArrayWithDictArray:(NSArray *)response {
    if ([response isKindOfClass:[NSArray class]]) {
        NSMutableArray *array = [self mj_objectArrayWithKeyValuesArray:response];
        return array;
    }
    return [NSMutableArray new];
}

+ (id)modelWithDictionary:(NSDictionary *)dictionary {
    if ([dictionary isKindOfClass:[NSDictionary class]]) {
        return [self mj_objectWithKeyValues:dictionary];
    }
    return [[self alloc] init];
}

+ (void)setUpModelClassInArrayWithContainDict:(NSDictionary *)dict {
    if (dict.allKeys.count == 0) {
        return ;
    }
    [self mj_setupObjectClassInArray:^NSDictionary *{
        return dict;
    }];
}

+ (NSMutableArray *)modelArrayWithDictArray:(NSArray *)response containDict:(NSDictionary *)dict {
    if (dict == nil) {
        dict = [NSMutableDictionary new];
    }
    [self setUpModelClassInArrayWithContainDict:dict];
    return [self modelArrayWithDictArray:response];
}

+ (id)modelWithDictionary:(NSDictionary *)dictionary containDict:(NSDictionary *)dict {
    if (dict == nil) {
        dict = [NSMutableDictionary new];
    }
    [self setUpModelClassInArrayWithContainDict:dict];
    return [self modelWithDictionary:dictionary];
}

- (id)unarchiver {
    id obj = [CJFileCacheManager getObjectByFileName:[self.class description]];
    return obj;
}

- (void)archive {
    [CJFileCacheManager saveObject:self byFileName:[self.class description]];
}

- (void)remove {
    [CJFileCacheManager removeObjectByFileName:[self.class description]];
}
@end
